#include <iostream>
using namespace std;

int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    int sum1=0,sum0=0;
    int ans = 0;
    for(int i = 0 ;i<s.size();i++)
    {
        if(s[i]=='0')
        {
            sum0++;
        }
        else
        {
            sum1++;
        }
    }
    s = s + s;
    int l = 0,r = 0,sum00=0,sum11=0;
    while(r < 3*n/2-1)
    {
        // cout << s[r] << " ";
        if(s[r++] == '0')
        {
            sum00++;
        }
        else {
            sum11++;
        }
        while(sum00*2 > sum0 || sum11*2 > sum1)
        {
            if(s[l++] == '0')
            {
                sum00--;
            }
            else {
                sum11--;
            }
        }
        if(sum00*2 == sum0 && sum11*2 == sum1)
        {
            ans++;
        }
    }
    // cout << endl;
    cout << ans << endl;

    return 0;
}
// 64 位输出请用 printf("%lld")